#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const int M = 1e9+7;

struct Edge {
    int from, to, w;
    bool operator< (const Edge& T) {
        return w < T.w;
    }
} e[N];

int n;

int f[N], sum[N];

void init() {
    for (int i = 0; i < N; i++) {
        f[i] = i;
        sum[i] = 1;
    }
}

int find(int x) {
    return f[x] == x ? x : f[x] = find(f[x]);
}

void merge (int x, int y) {
    x = find(x), y = find(y);
    if (x != y) {
        f[y] = x;
        sum[x] += sum[y];
    }
}

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    init();

    int n;
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        e[i] = {u, v, w};
    }

    sort(e, e+n-1);

    ll res = 0;
    for (int i = 0; i < n-1; i++) {
        int u = find(e[i].from), v = find(e[i].to), w = e[i].w;

        res += (ll)sum[u] * sum[v] * w;
        merge(u, v);
    }

    cout << res << endl;
    return 0;
}